﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace KewlStuff.Extensions
{
    public static class StringExtensions
    {
        public static bool Contains(this string source, string toCheck, StringComparison comp)
        {
            return source.IndexOf(toCheck, comp) >= 0;
        }

        public static bool ContainsIgnoreCase(this string source, string toCheck)
        {
            return Contains(source, toCheck, StringComparison.OrdinalIgnoreCase);
        }

        public static string JoinString<T>(this IEnumerable<T> source, string seperator)
        {
            var strs = source.Select(o => "" + o);
            var sb = new StringBuilder(strs.Select(s => s.Length).Sum() + strs.Count() * seperator.Length);
            bool first = true;
            foreach (var s in strs)
            {
                if (!first) sb.Append(seperator);
                first = false;
                sb.Append(s);
            }
            return sb.ToString();
        }
    }
}
